﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Routing;

namespace BasicCMS.Modules
{
    public abstract class ModuleBase : IModule
    {
        /// <summary>
        /// 模块名称
        /// </summary>
        public abstract string ModuleName { get; }

        /// <summary>
        /// 模块初始化
        /// </summary>
        public virtual void Initialize() { }

        /// <summary>
        /// 注册路由
        /// </summary>
        public virtual void RegisterRoutes() { }

        /// <summary>
        /// 注册过滤器
        /// </summary>
        /// <param name="globalFilters"></param>
        public virtual void RegisterFilters(GlobalFilterCollection filters) { }

        /// <summary>
        /// 注册ModelBinders
        /// </summary>
        /// <param name="modelBinders"></param>
        public virtual void RegisterModelBinders(ModelBinderDictionary modelBinders) { }

        #region MapRoute
        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        protected void MapRoute(string name, string url)
        {
            RouteTable.Routes.MapRoute(name, url, null, null, null, ModuleName);
        }

        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        protected void MapRoute(string name, string url, object defaults)
        {
            RouteTable.Routes.MapRoute(name, url, defaults, null, null, ModuleName);
        }

        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="namespaces"></param>
        protected void MapRoute(string name, string url, string[] namespaces)
        {
            RouteTable.Routes.MapRoute(name, url, null, null, namespaces, ModuleName);
        }

        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        /// <param name="constraints"></param>
        protected void MapRoute(string name, string url, object defaults, object constraints)
        {
            RouteTable.Routes.MapRoute(name, url, defaults, constraints, null, ModuleName);
        }

        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        /// <param name="namespaces"></param>
        protected void MapRoute(string name, string url, object defaults, string[] namespaces)
        {
            RouteTable.Routes.MapRoute(name, url, defaults, null, namespaces, ModuleName);
        }

        /// <summary>
        /// MapRoute
        /// </summary>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        /// <param name="constraints"></param>
        /// <param name="namespaces"></param>
        protected void MapRoute(string name, string url, object defaults, object constraints, string[] namespaces)
        {
            RouteTable.Routes.MapRoute(name, url, defaults, constraints, namespaces, ModuleName);
        }
        #endregion
    }
}
